<?php
namespace App\controller;
use Core\Db;
use Slim\Views\PhpRenderer;
use App\model\ocrModel;
use App\model\aesModel;
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response; 

class homeController
{
    
	public function test($request,$res,$args){
		echo 2234;
		/*
		$res = '7PrZ5d4ZJuVaI98MgxpP+YDMHj9ua7geW2ViAockNo1CcFRxr+SxK3BSeRouSHQudUpHgCcccKXQSV823jPRA7X4QRqV01IkP3CXITwPCi5Wtv0vorSLtSUz8RGRhaHlRgB751JOC4rUF9xY5wrdAg==';
		$aesModel=new aesModel();
		$token_info=$aesModel->aesDe($res);
		$token_arr=json_decode($token_info,true); 
		if(empty($token_arr)){
			exit('错误1');
		}
		$accesstoken=$token_arr['accessToken'];
		*/ 
		$userinfo=array("id"=>5003074187294, "name"=>  "测试账号家长" ,"type"=>1,  "nickName"=> "测试账号", "province"=> "2139", "provinceName"=> "广东","xxtState"=>0,"head100"=>"http://edu.10086.cn/test-upload/head/default_a3.jpg", "classes"=> array(
			0=> array(
				"id"=> 3391922350,"name"=> "一年级一班" ,"typeId"=>3,"type"=> "小学一年级","schoolId"=> 5432874297,"schoolName"=>"测试学校"
			)
	),"internetRole"=> NULL ,"telephoneNO"=> "HhDlDTUoZzbuw8t6IomEfeoomTY3Q3yH8O8ZPqeHGSexVO/3AlYKXsAiEPhevAI9wMRtO/SbMGQxV4k5RvCEok4o4ENdlFYAoo8N1t42/vfbuRx+iyMr33OwocZLZ+ivk7gRUcZZhMGA9vOjTviNW47b2yRxkFPtINxOV8u5+Bw=","loginChannelId"=> NULL);
	$uid = Db::table()->get("bbx_user", "uid", [
		"uid" => $userinfo['id']
	]);
	if(empty($uid)){
		Db::table()->insert("bbx_user", [
			"uid" => $userinfo['id'],
			"name" => $userinfo['name'],
			"nickName" => $userinfo['nickName'],
			"provinceName" => $userinfo['provinceName'],
			"head100" => $userinfo['head100'],
			"schoolName" => $userinfo['classes'][0]['schoolName'],
			"levelName" =>  $userinfo['classes'][0]['type'],
			"className" =>$userinfo['classes'][0]['name'],  
			"ctime" => time()
		]);
		}
		var_dump( Db::table()->log() );

		die;
	} 
	public function getOcr($request,$res,$args){
 
		$ocr=new ocrModel();  
		$file=ROOT_PATH.'/public/static/20191012112309.png';
		 $cfile = curl_file_create($file, 'image/jpeg'); 
		$text=$ocr->ocrPic($cfile);
		$r=explode('\n',$text);
		var_dump($r);
		die;
	}
	//导入高分作文 名校作文
	public function import_sql($request,$res,$args){
			 
		set_time_limit(60);
		ini_set("memory_limit", "128M"); 
		//引入PHPExcel文件
		require 'PHPExcel.php';
		 
		//创建excel读对象
		//$reader = \PHPExcel_IOFactory::createReader('Excel5')->setInputEncoding('GBK');
		//得到excel操作对象
		$excel = \PHPExcel_IOFactory::load(ROOT_PATH.'/public/static/demo2.xlsx');
		 
		//放入数组
		$data = array();
		 
		//获取所有工作表名
		$SheetNamas = $excel->getSheetNames();
		//遍历工作表 
		//获取当前工作表名
		$SheetName = $SheetNamas[0];
		//根据表名切换当前工作表
		$excel->setActiveSheetIndexByName($SheetName);
		//得到当前工作表对象
		$curSheet = $excel->getActiveSheet();
		//获取当前工作表最大行数
		$rows = $curSheet->getHighestRow();
		//获取当前工作表最大列数,返回的是最大的列名，如：B 
		$cols = $curSheet->getHighestColumn();
	 
		//将当前工作表名当键，内容为值存入数组
		$data[$SheetName] = array();
		echo $rows;
	 
		//大写字母A的ASCII值是65 A-Z对应65-90
		for($k = 2; $k <= $rows; $k++){
			$data=array();
			$data['title'] = $curSheet->getCell("A".$k)->getValue();
			$data['requirement'] = $curSheet->getCell("B".$k)->getValue();
			$data['essay'] = $curSheet->getCell("C".$k)->getValue();
			$data['genre'] = $curSheet->getCell("D".$k)->getValue();
			$data['topic'] = $curSheet->getCell("E".$k)->getValue();
			$data['tags'] = $curSheet->getCell("G".$k)->getValue();
			$data['origin'] = $curSheet->getCell("F".$k)->getValue();
			$data['tip'] =2;
			$data['ctime'] =time();  
			if($data['title'] && $data['requirement']){
			  Db::table()->insert("bbx_model",$data);
			}
		}
	} 
	//导入学霸作文
	public function import_sql_fines($request,$res,$args){
			 
		set_time_limit(60);
		ini_set("memory_limit", "128M"); 
		//引入PHPExcel文件
		require 'PHPExcel.php';
		 
		//创建excel读对象
		//$reader = \PHPExcel_IOFactory::createReader('Excel5')->setInputEncoding('GBK');
		//得到excel操作对象
		$excel = \PHPExcel_IOFactory::load(ROOT_PATH.'/public/static/demo2.xlsx');
		 
		//放入数组
		$data = array();
		 
		//获取所有工作表名
		$SheetNamas = $excel->getSheetNames();
		//遍历工作表 
		//获取当前工作表名
		$SheetName = $SheetNamas[0];
		//根据表名切换当前工作表
		$excel->setActiveSheetIndexByName($SheetName);
		//得到当前工作表对象
		$curSheet = $excel->getActiveSheet();
		//获取当前工作表最大行数
		$rows = $curSheet->getHighestRow();
		//获取当前工作表最大列数,返回的是最大的列名，如：B 
		$cols = $curSheet->getHighestColumn();
	 
		//将当前工作表名当键，内容为值存入数组
		$data[$SheetName] = array();
		echo $rows;
	 
		//大写字母A的ASCII值是65 A-Z对应65-90
		for($k = 2; $k <= $rows; $k++){
			$data=array();
			$data['title'] = $curSheet->getCell("F".$k)->getValue();
			$data['requirement'] = $curSheet->getCell("G".$k)->getValue();
			$data['essay'] = $curSheet->getCell("H".$k)->getValue();
			$data['graduate'] = $curSheet->getCell("B".$k)->getValue();
			$data['name'] = $curSheet->getCell("C".$k)->getValue();
			$data['level'] = $curSheet->getCell("D".$k)->getValue();
			$data['tip'] =2;
			$data['ctime'] =time();  
			if($data['title'] && $data['requirement']){
			  Db::table()->insert("bbx_fines",$data);
			}
		}
	} 	
} 